<#assign className = table.className>
<#assign classNameLower = className?uncap_first>
<#assign serviceName = classNameLower+"Service">
import * as ${serviceName} from '../services/${className+"Service"}';

export default {
  namespace: '${classNameLower}',
  state: {
    list: [],
    total: null,
    page: null,
    detailData:null,
  },
  reducers: {
    save(state, { payload: {data:list, total, page } }) {
      list.forEach(item=>{
        let s=new Date(item.createDatetime*1);
        item.createDatetime=s.toLocaleString()
      });
      return { ...state, list, total, page };
    },
  },
  effects: {
    *fetch({ payload: { page = 1 } }, { call, put }) {
      const rs = yield call(${serviceName}.getList, { page });
      const { data} =rs;         
      yield put({
        type: 'save',
        payload: {
          data:data.records,
          total:data.total,
          page: data.current,
        },
      });
    },
    *remove({ payload: id }, { call, put, select }) {
      yield call(${serviceName}.remove, id);
      const page = yield select(state => state.${classNameLower}.page);
      yield put({ type: 'fetch', payload: { page } });
    },
    *patch({ payload: { id, values } }, { call, put, select }) {     
      
      yield call(${serviceName}.patch, id, values);
      const page = yield select(state => state.${classNameLower}.page);
      yield put({ type: 'fetch', payload: { page } });
    },
    *add({ payload: {values } }, { call, put, select }) {
      yield call(${serviceName}.add,values);
      const page = yield select(state => state.${classNameLower}.page);
      yield put({ type: 'fetch', payload: { page } });
    }    
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname, query }) => {
        if (pathname === '/${classNameLower}') {
          dispatch({ type: 'fetch', payload: query });
        }

      });
    },
  },
};